<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class CheckIsLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     *
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        $whiteList = [
            'api/login',
            'api/ding/userId',
            'api/ding/lineBusNum',
            'api/dictData',
            'api/ding/materialList',
            'api/ding/putMaterialList',
            'api/ding/putMaterialInfo',
            'api/ding/putMaterialInfo',
            'api/ding/addMaterial',
            'api/ding/editMaterial',
            'api/ding/editAddPutMaterialDetail',
            'api/ding/editMaterialDetail',
            'api/ding/editDelPutMaterialDetail',
            'api/ding/delPutMaterial',
            'api/ding/toAuditPut',
            'api/ding/outMaterialList',
            'api/ding/addOutMaterial',
            'api/ding/outMaterialInfo',
            'api/ding/editOutMaterial',
            'api/ding/editOutMaterialDetail',
            'api/ding/editAddOutMaterialDetail',
            'api/ding/editDelOutMaterialDetail',
            'api/ding/delOutMaterial',
            'api/ding/toAuditOut',
            'api/ding/tyreOutMaterialList',
            'api/ding/addTyreOutMaterial',
            'api/ding/tyreOutMaterialInfo',
            'api/ding/editTyreOutMaterial',
            'api/ding/editTyreOutMaterialDetail',
            'api/ding/editAddTyreOutMaterialDetail',
            'api/ding/editDelTyreOutMaterialDetail',
            'api/ding/delTyreOutMaterial',
            'api/ding/toAuditTyreOut',
            'api/ding/myMaterialList',
            'api/ding/getUser',
            'api/upload/signFile',
            //维修
            'api/licensePlateNumList',
            'api/upload/mrSignFile',
            'api/ding/upload/file',
            'api/ding/applyList',
            'api/ding/editApply',
            'api/ding/storeApply',
            'api/ding/storeWeixiu',
            'api/ding/updateApply',
            'api/ding/destroyApply',
            'api/ding/mrApply/audit',
            // 掉趟
            'api/ding/dropTripList',
            'api/ding/storeDropTrip',
            'api/ding/deleteDropTrip',
            'api/ding/isBusNum',
            // 司机签到
            'api/ding/attendanceList',
            //车队长上报
            'api/ding/storeAttendance',
            //获取车队长上报类型
            'api/ding/getReportType',
            'api/ding/deleteAttendance',
            //获取考勤列表
            'api/ding/attendanceStatusList',
            //按车牌号查看考勤详情
            'api/ding/busDetailData',
            //按驾驶员查看考勤详情
            'api/ding/driverDetailData',
            //修改打卡记录中间表数据
            'api/ding/updateAttendanceStatus',
            //修改车辆(驾驶员)汇总数据
            'api/ding/updateCollectData',
            //获取所有线路数组
            'api/ding/getLines',
        ];
        $uri = $request->route()->uri();
        if (! in_array($uri, $whiteList)) {
            if (! Auth::check()) {
                return response()->json(['result' => '登录失效，请重新登陆'], 401);
            }
        }
        return $next($request);
    }
}
